package com.mew.chess.core.common.handler;

import com.mew.common.entity.config.Game;

import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;

public class GameInfoMananger {
    private static GameInfoMananger gameInfoMananger = new GameInfoMananger();
    private final ConcurrentMap<Integer, Game> roomCache = new ConcurrentHashMap<>(4);
    private GameInfoMananger(){}

    public static GameInfoMananger getInstance() {
        if (gameInfoMananger == null) {
            synchronized (GameInfoMananger.class) {
                if (gameInfoMananger == null) {
                    gameInfoMananger = new GameInfoMananger();
                }
            }
        }
        return gameInfoMananger;
    }


    public void put(Game game){
        roomCache.put(game.getId(), game);
    }

    public void remove(int roomId){
        roomCache.remove(roomId);
    }

    public Game get(int gameId){
        return roomCache.get(gameId);
    }


}
